//==================================================================
//  Copyright (C) 2006-2007  Davide Pasca
//
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//==================================================================
/// @file
///
///
/// 
/// @author Davide Pasca
/// 
//==================================================================

#include "stdafx.h"
#include "rend_system.h"

//==================================================================
///
//==================================================================
RendSystem::RendSystem()
{
#ifdef TARGET_D3D
	// Create the D3D object.
	if ERR_NULL( _contextp = Direct3DCreate9( D3D_SDK_VERSION ) )
	{
		throw "sad !";
	}
#else
	_contextp = NULL;
#endif
}

//==================================================================
RendSystem::~RendSystem()
{
	_contextp = NULL;
}

//==================================================================
RendDevice	*RendSystem::NewRendDevice( u_int w, u_int h, const TCHAR *basepathp )
{
	RendDevice	*devp;

	devp = new RendDevice( _contextp, w, h, basepathp );

	return devp;
}

//==================================================================
namespace PSYS {

//==================================================================
PError GLErrorCheck( const TCHAR *srcfnamep, int line )
{
#ifdef __GL_H__
	int	err = glGetError();

	if ( err )
	{
		// $$$ not good enough.. on JP windows this is shift-jis or something !
		TCHAR	*err_tchp = PSYS::ANSIToTCHAR( (const char *)gluErrorString(err) );
		PDEBUG_PRINTF( _T("GL Error: %s [%s line %d] \n"), err_tchp, srcfnamep, line );
		delete [] err_tchp;
		return PERROR;
	}
	else
#endif
		return POK;
}

}